package com.sign.common.util.validateCode;

import com.ly.common.Contants;

import java.util.Random;

/**
 * @program: blog
 * @description: ${description}
 * @author: JunPingXiao
 * @create: 2021-05-07 15:22
 **/
public class RandomCode {

    public static void main(String[] args) {
        String randomCode = getRandomCode(Contants.RANDOM_CODE, 6);
        System.out.println(randomCode);
    }

    public static String getRandomCode(char[] chars,int length){
        StringBuffer buffer = new StringBuffer();
        Random random = new Random();
        for (int i = 0; i < length; i++) {
            buffer.append(chars[random.nextInt(chars.length)]);
        }
        return buffer.toString();
    }
}
